package com.huangj.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huangj.entity.HomeInfoEntity;
import com.huangj.pro2_h2pop.HomeInfoMapActivity;
import com.huangj.pro2_h2pop.R;
import com.huangj.wedigt.MyListview;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by HuangJ on 2016/10/5.17:16
 */
public class HomeInfoRoteAdapter extends BaseAdapter{

    private Context context;
    private List<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.DaysBean> datas;
    private RoteChildAdapter roteChildAdapter;

    public HomeInfoRoteAdapter(Context context) {
        this.context = context;
        this.datas = new ArrayList<>();
    }
    public void setDatas(List<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.DaysBean> datas){
        this.datas = datas;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView != null){
            viewHolder = (ViewHolder) convertView.getTag();
        }else {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_jdrote,null);
            viewHolder.didian = (TextView) convertView.findViewById(R.id.diddian);
            viewHolder.days = (TextView) convertView.findViewById(R.id.days);
            viewHolder.description = (TextView) convertView.findViewById(R.id.description);
            viewHolder.rote_ll = (LinearLayout) convertView.findViewById(R.id.rote_llditu);

            //内部listView;
            viewHolder.rotechildlv = (MyListview) convertView.findViewById(R.id.lv_roteitem);

            convertView.setTag(viewHolder);
        }
        viewHolder.days.setText(datas.get(position).getPosition()+"");
        viewHolder.description.setText(datas.get(position).getDescription());
        viewHolder.didian.setText(datas.get(position).getPoints().get(0).getInspiration_activity().getDestination().getName());
        //内部的ListView的数据；
        List<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.DaysBean.PointsBean> points =
                datas.get(position).getPoints();
        roteChildAdapter = new RoteChildAdapter(context);
        roteChildAdapter.setDatas(points);
        viewHolder.rotechildlv.setAdapter(roteChildAdapter);

        viewHolder.rotechildlv.setSelection(0);

        //LinearLayout 的点击事件；
        viewHolder.rote_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.DaysBean.PointsBean> pointsBeen = (ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.DaysBean.PointsBean>) datas.get(position).getPoints();
//                datas = new ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.DaysBean>();
                Intent intent = new Intent(context, HomeInfoMapActivity.class);
                intent.putExtra("datas",(ArrayList)datas);
                context.startActivity(intent);
            }
        });
        return convertView;
    }
    class ViewHolder{
        TextView days,didian,description;
        MyListview rotechildlv;
        LinearLayout rote_ll;
    }
}
